﻿<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Demo</title>
	<link href="//unpkg.com/layui@2.10.1/dist/css/layui.css" rel="stylesheet">
</head>
<body>
	<form class="layui-form" action="" id="baseStoreForm">
		<label class="layui-input-inline" style="width:auto">单据编码</label>
		<div class="layui-input-inline">
			<input type="text" id="orderCode" name="orderCode" class="layui-input">
		</div>
		<button class="layui-btn" lay-submit lay-filter="search">查询</button>
		<button type="reset" class="layui-btn layui-btn-primary">重置</button>
		<button id="save-btn" class="layui-btn" lay-submit lay-filter="TosubmitAdd">
			<i class="layui-icon">&#xe608;</i> 新增数据			
		</button>
		<b><a href="http://localhost:8075/webroot/decision/view/duchamp?viewlet=%25E6%2598%258E%25E7%25BB%2586%25E8%25A1%25A8%252F%25E9%2594%2580%25E5%2594%25AE%25E9%2580%2580%25E8%25B4%25A7%25E6%2598%258E%25E7%25BB%2586%25E6%258A%25A5%25E8%25A1%25A8.fvs&page_number=1" style="color:blue" target="_blank">销售退货报表(帆软报表)</a></b>
		<b><a href="http://localhost:8075/webroot/decision/view/report?viewlet=%25E6%2598%258E%25E7%25BB%2586%25E8%25A1%25A8%252F%25E9%2587%2587%25E8%25B4%25AD%25E8%25AE%25A2%25E5%258D%2595%25E6%2598%258E%25E7%25BB%2586%25E6%258A%25A5%25E8%25A1%25A81.cpt" style="color:green" target="_blank">采购订单明细报表(帆软报表)</a></b>
		<b><a href="http://localhost:8075/webroot/decision/view/duchamp?viewlet=%25E6%2598%258E%25E7%25BB%2586%25E8%25A1%25A8%252F%25E7%259C%258B%25E6%259D%25BF.fvs&page_number=1" style="color:red" target="_blank">看板(帆软报表)</a></b>
	</form>

	<table class="layui-hide" id="table_row"></table>

	<script src="//unpkg.com/layui@2.10.1/dist/layui.js"></script>

	<script>
		layui.use(['table', 'jquery', 'layer', 'form', 'laydate'],function(){
			var table = layui.table;
			var $ = layui.jquery;
			var layer = layui.layer;
			var form = layui.form;
			var laydate = layui.laydate;

			form.on('submit(TosubmitAdd)', function(data){
				window.location.href = 'AddMement';
				return false; // 阻止表单默认提交
			});

			//初始化表格
			table.render({
				toolbar: '#toolbarDemo',
				defaultToolbar: ['filter', 'exports', 'print', { // 右上角工具图标
				  title: '提示',
				  layEvent: 'LAYTABLE_TIPS',
				  icon: 'layui-icon-tips',
				  onClick: function(obj) { // 2.9.12+
				  layer.alert('自定义工具栏图标按钮');
				  }
				}],
				height: 'full-35', // 最大高度减去其他容器已占有的高度差
				css: [ // 重设当前表格样式
				  '.layui-table-tool-temp{padding-right: 145px;}'
				].join(''),
				cellMinWidth: 80,
				totalRow: true, // 开启合计行
				elem: '#table_row',
				id: 'BaseStoretable',
				height: '500',
				cols:[[
					{ field: 'oid', width: 80, sort: true, fixed: 'left', title: 'id' },
					{ field: 'orderCode', width: 180, title: '采购订单' },
					{ field: 'getMaintitle', width: 80, title: '采购主题' },
					{ field: 'supplierName', width: 80, title: '供应商' },
					{
						field: 'saleDate',
						width: 180,
						title: '采购日期',
						templet: function(d) {
							if (!d.saleDate) return '';

							const date = new Date(d.saleDate);

							// 获取年月日时分秒
							const year = date.getFullYear();
							const month = String(date.getMonth() + 1).padStart(2, '0');
							const day = String(date.getDate()).padStart(2, '0');
							const hours = String(date.getHours()).padStart(2, '0');
							const minutes = String(date.getMinutes()).padStart(2, '0');
							const seconds = String(date.getSeconds()).padStart(2, '0');

							return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
						}
					},
					{ field: 'byDepart', width: 80, title: '采购部门' },
					{ field: 'byName', width: 80, title: '采购人员' },
					{ field: 'sumMoney', width: 80, title: '总金额' },
					{ field: 'yfuMoney', width: 80, title: '已付金额' },
					{ field: 'ydpMoney', width: 80, title: '已到票金额' },
					{ field: 'shenpStuct', width: 80, title: '审批状态' ,
						templet:function(d){
							if(d.shenpStuct==1){
								return '待审批'
							}
							else if(d.shenpStuct==2){
								return '审批中'
							}
							else if(d.shenpStuct==3){
								return '已通过'
							}
							else if(d.shenpStuct==4){
								return '已拒绝'
							}
						}
					},
					{ field: 'fukuanStuct', width: 80, title: '付款状态' },
					{ field: 'rukuStuct', width: 80, title: '入库状态' },
					{ field: 'dpiaoStuct', width: 80, title: '到票状态' },
					{ fixed: 'right', width: 100, align: 'center', toolbar: '#barDemo', title: '操作' }
				]],
			});

			// 表格操作按钮
			table.on('tool(BaseStoretable)', function(obj){
				var data = obj.data;
				if(obj.event === 'detail'){
					// 跳转到详情页，携带当前行数据
					window.location.href = 'PurchaseOrderDetail?data=' + encodeURIComponent(JSON.stringify(data));
				}
			});

			function loadRoleData(){
				var parms={
					orderCode: $('#orderCode').val() || '',
				}
				$.ajax({
					url:'http://localhost:5234/api/MyOrderMement/GetOrderMement',
					//url: "@ViewBag.BaseUrl/T7/MyOrderMement/GetOrderMement",
					data: parms,
					type: 'get',
					dataType: 'json',
					success: function (res){
						console.log(res.data);
						layer.closeAll('loading');
						if (res.code === 210) {
							table.reload('BaseStoretable', {
								data: res.data,
							});
						}
						else {
							layer.msg('获取数据失败: ' + (res.message || '未知错误'), { icon: 2 });
						}
					},
					error: function (xhr, status, error) {
						layer.closeAll('loading');
						layer.msg('请求失败: ' + error, { icon: 2 });
						console.error('Ajax请求失败:', xhr.responseText);
					}
				})
			}

			// 搜索按钮点击事件
			form.on('submit(search)', function (data) {
				loadRoleData();
				return false; // 阻止表单跳转
			});

			// 页面加载完成后获取数据
			loadRoleData();
		});
	</script>

	<!-- 操作按钮模板 -->
	<script type="text/html" id="barDemo">
		<a class="layui-btn layui-btn-xs" lay-event="detail">查看</a>
	</script>
</body>
</html>